using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.ObjectBuilder;
using Microsoft.Practices.CompositeWeb;
using System.Transactions;
using GC2.Entities.Admin;
using GC2.ExceptionHandler.Services;
using GC2.DataAccess.DAAdmin;

namespace GC2.Bussines.BMAdmin
{
    public class BMConceptos
    {
        public BMConceptos(string coneccion) 
        {
            this.Connection = coneccion;
        }

        private string connection = "";
        public string Connection
        {
            get { return connection; }
            set { connection = value; }
        }

        private Conceptos oConceptos = new Conceptos();
        private List<Conceptos> listaConceptos = new List<Conceptos>();
        private DAConceptos daConceptos = new DAConceptos();

        #region BMConceptosSearch
        public List<Conceptos> BMConceptosSearch(Conceptos concepto)
        {
            try
            {
                List<Conceptos> listaTemp = new List<Conceptos>();
                listaConceptos = new List<Conceptos>();
                listaTemp = daConceptos.DAConceptosSearch(connection, concepto);
                foreach (Conceptos item in listaTemp)
                {
                    //if (item.Id_Concepto > 1000)
                    //{
                    //    listaConceptos.Add(item);
                    //}
                    listaConceptos.Add(item);
                }

                return listaConceptos;
            }
            catch (Exception ex)
            {
                ExceptionBM exNew = new ExceptionBM();
                throw new System.Exception(exNew.exBM(ex.ToString()).ToString());
            }
        }
        #endregion

        #region BMConceptosInsert
        public void BMConceptosInsert(Conceptos concepto)
        {
            try
            {
                oConceptos = daConceptos.DAConceptosGetLast(connection);
                oConceptos.Id_Concepto++;
                concepto.Id_Concepto = oConceptos.Id_Concepto;
                if (concepto.Id_Tipo == 1)
                {
                    concepto.Tipo = "Egresos";
                }
                if (concepto.Id_Tipo == 2)
                {
                    concepto.Tipo = "Ingresos";
                }
                daConceptos.DAConceptosInsert(connection, concepto);
            }
            catch (Exception ex)
            {
                ExceptionBM exNew = new ExceptionBM();
                throw new System.Exception(exNew.exBM(ex.ToString()).ToString());
            }
        }
        #endregion

        #region BMConceptosUpdate
        public void BMConceptosUpdate(Conceptos concepto)
        {
            try
            {
                daConceptos.DAConceptosUpdate(connection, concepto);
            }
            catch (Exception ex)
            {
                ExceptionBM exNew = new ExceptionBM();
                throw new System.Exception(exNew.exBM(ex.ToString()).ToString());
            }
        }
        #endregion

        #region BMConceptosGetLast
        public Conceptos BMConceptosGetLast()
        {
            try
            {
                oConceptos = daConceptos.DAConceptosGetLast(connection);
                return oConceptos;
            }
            catch (Exception ex)
            {
                ExceptionBM exNew = new ExceptionBM();
                throw new System.Exception(exNew.exBM(ex.ToString()).ToString());
            }
        }
        #endregion
    }
}
